require(['./config'], () => {
    require(['template', 'header', 'footer'], (template) => {
        class List {
            constructor() {
                this.getData().then(() => {
                    this.render()
                    this.modify()
                })
                this.jump()
                this.modify()
            }
            getData() {
                const id = window.location.search.slice(1).split('&').reduce((obj, item) => {
                    var arr = item.split('=')
                    obj[arr[0]] = arr[1]
                    return obj
                }, {}).id
                this.id = Number(id)
                return new Promise(resolve => {
                    $.get('http://rap2.taobao.org:38080/app/mock/258745/api/list', { id: this.id }, resp => {
                        const aa = resp.body
                        this.aa = aa
                        resolve()
                    })
                })
            }
            render() {
                $('#list').html(template('listTmplate', {
                    ...this.aa
                }))
            }
            jump() {
                $('main').on('click', '.wares-list', e => {
                    const num = $(e.target).parent().data('id')
                    const jump = $('<a>').attr('href', `../../../html/list.html?num=${num}`)[0]
                    $(e.target).parent().attr('href', `../../../html/details.html?num=${num}`)
                })
            }
            modify(){
                let name = window.location.search.slice(1).split('&').reduce((obj, item) => {          
                    var arr = item.split('=')  
                    obj[arr[0]] = arr[1]                               
                    return obj
                }, {}).name
                let kind = window.location.search.slice(1).split('&').reduce((obj, item) => {          
                    var arr = item.split('=')  
                    obj[arr[0]] = arr[1]                               
                    return obj
                }, {}).kind
                name =decodeURI(name)
                kind =decodeURI(kind)
                $('.kind').html(name)
                $('.name').html(kind)         

            }
        }
        new List()
    })
})